package com.cn.ZhiKeDianShang.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.cn.ZhiKeDianShang.R;
import com.cn.ZhiKeDianShang.base.BaseActivity;
import com.cn.ZhiKeDianShang.model.response.UserInfoBean;
import com.cn.ZhiKeDianShang.presenter.LoginUserPresenter;
import com.cn.ZhiKeDianShang.presenter.view.LoginUserView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/3.
 * do what to 2017/7/3
 */

public class ChangeUserNameActivity extends BaseActivity<LoginUserView, LoginUserPresenter> implements LoginUserView {

    @BindView(R.id.et_name)
    EditText etName;

    String username;

    @Override
    protected int getNormalLayoutId() {
        return R.layout.activity_updateusername_info;
    }

    @Override
    protected int getErrorLayoutId() {
        return R.layout.activity_updateusername_info;
    }

    @Override
    protected LoginUserPresenter createPresenter() {
        return new LoginUserPresenter(this, this);
    }

    @Override
    protected void initViewsAndEvents() {
        username = getIntent().getStringExtra("username");
        if (!TextUtils.isEmpty(username)) {
            etName.setText(username);
        }
    }

    @Override
    public void onLogin(UserInfoBean resultBean) {

    }

    @Override
    public void requestFailed(String message) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.setting_back, R.id.tv_left})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.setting_back:
                finish();
                break;
            case R.id.tv_left:
                username = etName.getText().toString();
                // 设置返回数据
                Bundle bundle = new Bundle();
                bundle.putString("username", username);
                Intent intent = new Intent();
                intent.putExtras(bundle);
                // 返回intent
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }
}
